<?php
require('header.php');

echo "<h3>Order History</h3><br>";

$query = "SELECT * FROM purchase_history JOIN item ON purchase_history.itemID=item.part_no WHERE email='" . $_SESSION['email'] . "' ORDER BY date DESC";
if ($result = mysqli_query($con, $query)) {
		if (mysqli_num_rows($result) > 0) {
			while ($row = mysqli_fetch_array($result)) {
				$d = date("j-m-Y", strtotime($row['date']));
				$cancelled = ($row['cancelled'] ? "Yes" : "No");
				echo<<<EOT
				<strong>Date: $d</strong>
				<br>Name: $row[name]
				<br>Price: $row[price]
				<br>Quantity: $row[quantity]
				<br>Cancelled: $cancelled
				<br><br>
EOT;
			}
		} else {
			echo "You have not yet made any purchases.";
		}
	} else {
		echo "There was an error: " . mysqli_error($con) . "<br>";
	}

require('footer.php');
?>